package com.company.gas.controller;

import com.company.gas.pojo.Material;
import com.company.gas.service.IMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * @author: Li Guangdi
 *
 */
@RestController
@RequestMapping("/gas/material")
@Api(tags = "物资管理相关接口")
public class MaterialController {

    @Autowired
    private IMaterialService iMaterialService;

    //查询全部物资
    @GetMapping("/queryMaterialList")
    @ApiOperation("查询全部物资")
    public List<Material> queryMaterialList(){
        List<Material> materialList = iMaterialService.queryMaterialList();
        return materialList;
    }

    //根据matId查询指定物资
    @GetMapping("/queryMaterialById")
    @ApiOperation("根据matId查询指定物资")
    public Material queryMaterialById(@RequestParam(value = "物资ID") String matId){
        Material material = iMaterialService.queryMaterialById(matId);
        System.out.println(material);
        return material;
    }

    //添加一个物资
    @GetMapping("/addMaterial")
    @ApiOperation("增加一个物资")
    public String addMaterial(@RequestParam(value = "物资ID") String matId,@RequestParam(value = "物资名称") String matName,
                              @RequestParam(value = "物资储量") Integer store,
                              @RequestParam(value = "可用量") Integer available, @RequestParam(value = "标志") Integer flag,
                           @RequestParam(value = "创建者") String createBy, @RequestParam(value = "修改者") String modifyBy){
        int isAddMaterial = iMaterialService.addMaterial(matId,matName,store,available,flag,createBy,modifyBy);
        if(isAddMaterial == 1){
            return "add success";
        }else {
            return "add fail";
        }
    }

    //修改一个物资
    @GetMapping("/updateMaterial")
    @ApiOperation("修改一个物资")
    public String updateMaterial(@RequestParam(value = "物资ID") String matId,@RequestParam(value = "物资名称") String matName,
                                 @RequestParam(value = "物资储量") Integer store, @RequestParam(value = "可用量") Integer available,
                              @RequestParam(value = "标志") Integer flag,@RequestParam(value = "修改者") String modifyBy){
        int isUpdateMaterial = iMaterialService.updateMaterial(matId,matName,store,available,flag,modifyBy);
        if(isUpdateMaterial == 1){
            return "update success";
        }else {
            return "update fail";
        }
    }

    //根据matId删除指定物资
    @GetMapping("/deleteMaterial")
    @ApiOperation("根据matId删除指定物资")
    public String deleteMaterial(@RequestParam(value = "物资ID") String matId){
        int isDeleteMaterial = iMaterialService.deleteMaterial(matId);
        if(isDeleteMaterial == 1){
            return "delete success";
        }else {
            return "delete fail";
        }
    }
}
